'''
Created on 19/05/2009

@author: eh01
'''
from yarra.datastore.dso import DSO
from yarra.datastore.dst import DST
from yarra.datastore import dsofactory
import datetime
import unittest


class DSOFactoryTest(unittest.TestCase):

    def get_dummy_unsaved_dso_1(self):
        dst1 = DST(subject="dummySubject1", predicate="dummyPredicate1", object=None, literal="123", literal_type="int", xml_string=None)
        dst2 = DST(subject="dummySubject1", predicate="dummyPredicate2", object=None, literal="456", literal_type="int", xml_string=None)
        dso = DSO(created_timestamp=datetime.datetime.now())
        dso.type = "DummyDSO1"
        dso.uri = "/dummy/object1/uri"
        dso.add_dsts([dst1, dst2])
        return dso

    def setUp(self):
        pass


    def tearDown(self):
        pass

    def test_copy_dso_case_1(self):
        dso = self.get_dummy_unsaved_dso_1()
        copied_dso = dsofactory.copy_dso(dso)
        # '==' checks for equality while 'is' checks for object identity (i.e same space in memory)
        # hence this checks that the copied dso is equivalent but not the same object in memory
        if copied_dso == dso and not copied_dso is dso:
            assert True
        else:
            self.fail('Copied failed')


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_copy_dso_case_1']
    unittest.main()